<template>
  <div>
    <div style="padding:10px 0;" v-if="is_admin==0">最近一次登录时间 <span style="color:#409EFF">{{lastTime}}</span></div>
    <div style="padding:10px 0;">欢迎使用人协管理系统</div>
    <div style="padding:10px 0;" v-if="companyDetail.name&&is_admin==0">单位名称：{{companyDetail.name}}</div>
    <div style="padding:10px 0;" v-if="companyDetail.unit_grade_name&&is_admin==0">单位级别：{{companyDetail.unit_grade_name}}</div>
  </div>
</template>

<script>
  export default {
    name: "welcome",
    data(){
      return{
        userInfo: '',
        companyDetail:'',
        lastTime: window.localStorage.getItem('last_time'),
        is_admin: window.localStorage.getItem('is_admin')||0,
      }
    },
    methods:{
      async showConsultation() {
        //获取详情
        let res = await this.$api.getUnitDetail({id: window.localStorage.getItem('unit_id')});
        if (res.data.level == 'success') {
          console.log(res.data)
          this.companyDetail = res.data.data
        } else {
          this.$message.error(res.data.message)
        }
      },
      //获取用户信息
      async getUserInfo(){
        let params = {
          user_token: window.localStorage.getItem('user_token')
        }
        const res = await this.$api.getUserDetail(params)
        if(res.data.level=='success'){
          this.userInfo = res.data.data
        }else{
          this.$message({
            message: res.data.message,
            type: 'warning'
          });
        }
      },
      toData(){
        if(this.is_admin == 1)
          this.$router.push({ path: '/data' })
      }
    },
    mounted() {
      this.getUserInfo();
      this.showConsultation();
      this.toData();
    }
  }
</script>

<style scoped>

</style>
